package PenTest.xiaohongshu.ACM0409;

import java.util.*;

public class Acm2 {
    public static void main(String[] args) {
        //算法思想：使用优先队列对评论数排序，然后取出大于当前评论数的点赞数最多的求和计算最终值
        Scanner sc = new Scanner(System.in);
        String[] input = new String[3];
        for (int i = 0; i < 3; i++) {
            input[i] = sc.nextLine();
        }
        int n = Integer.parseInt(input[0].split(" ")[0]);
        int k = Integer.parseInt(input[0].split(" ")[1]);
        //
        ArrayList<int[]> arrayList = new ArrayList<>();
        String[] s1 = input[1].split(" ");
        String[] s2 = input[2].split(" ");
        for (int i = 0; i < n; i++) {
            int[] arr = new int[2];
            arr[0] = Integer.parseInt(s1[i]);
            arr[1] = Integer.parseInt(s2[i]);
            arrayList.add(arr);
        }
        Collections.sort(arrayList, new Comparator<int[]>() {
            @Override
            public int compare(int o1[], int o2[]) {
                return o2[1] - o1[1];
            }
        });
        //排序完成后，使用优先队列
        int sum=0;
        int ans=0;
        PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });
        for (int i = 0; i < arrayList.size(); i++) {
            pq.offer(arrayList.get(i)[0]);//最大的k-1个不可能为最小值
            sum+=arrayList.get(i)[0];
            if (pq.size() >= k) {
                ans=Math.max(ans,sum*arrayList.get(i)[1]);
                sum-=arrayList.get(i)[0];
                pq.poll();
            }
        }
        System.out.println(ans);
    }
}
